/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vamprest;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author sav
 */
@Entity
@Table(name = "vehiclestatus")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Vehiclestatus.findAll", query = "SELECT v FROM Vehiclestatus v"),
    @NamedQuery(name = "Vehiclestatus.findLastForIdVehicle", query = "SELECT v FROM Vehiclestatus v "
         +" WHERE v.idvehicle.idvehicle =:idvehicle1 and v.timestamp=(select max(s.timestamp) from Vehiclestatus s where s.idvehicle.idvehicle = :idvehicle2)"),
    @NamedQuery(name = "Vehiclestatus.findByTimestamp", query = "SELECT v FROM Vehiclestatus v WHERE v.timestamp = :timestamp")})
public class Vehiclestatus implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idvehiclestatus")
    private Integer idvehiclestatus;
    @Basic(optional = false)
    @NotNull
    @Column(name = "timestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;
    @Lob
    @Size(max = 65535)
    @Column(name = "comment")
    private String comment;
    @JoinColumn(name = "idvehicle", referencedColumnName = "idvehicle")
    @ManyToOne(optional = false)
    private Vehicle idvehicle;
    @JoinColumn(name = "idstatus", referencedColumnName = "idstatus")
    @ManyToOne(optional = false)
    private Status idstatus;
    @JoinColumn(name = "idgpslocation", referencedColumnName = "idgpslocation")
    @ManyToOne
    private Gpslocation idgpslocation;

    public Vehiclestatus() {
    }

    public Vehiclestatus(Integer idvehiclestatus) {
        this.idvehiclestatus = idvehiclestatus;
    }

    public Vehiclestatus(Integer idvehiclestatus, Date timestamp) {
        this.idvehiclestatus = idvehiclestatus;
        this.timestamp = timestamp;
    }

    public Integer getIdvehiclestatus() {
        return idvehiclestatus;
    }

    public void setIdvehiclestatus(Integer idvehiclestatus) {
        this.idvehiclestatus = idvehiclestatus;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Vehicle getIdvehicle() {
        return idvehicle;
    }

    public void setIdvehicle(Vehicle idvehicle) {
        this.idvehicle = idvehicle;
    }

    public Status getIdstatus() {
        return idstatus;
    }

    public void setIdstatus(Status idstatus) {
        this.idstatus = idstatus;
    }

    public Gpslocation getIdgpslocation() {
        return idgpslocation;
    }

    public void setIdgpslocation(Gpslocation idgpslocation) {
        this.idgpslocation = idgpslocation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idvehiclestatus != null ? idvehiclestatus.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Vehiclestatus)) {
            return false;
        }
        Vehiclestatus other = (Vehiclestatus) object;
        if ((this.idvehiclestatus == null && other.idvehiclestatus != null) || (this.idvehiclestatus != null && !this.idvehiclestatus.equals(other.idvehiclestatus))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "vamprest.Vehiclestatus[ idvehiclestatus=" + idvehiclestatus + " ]";
    }

}
